# -*- coding: utf-8 -*-
# @Author: Tim Liu
# @Date: 2024-05-25
# @Last Modified by: Tim Liu
# @Last Modified time: 2024-05-25

# @Description: Knowledge Base for RAG

from sqlalchemy.orm import relationship, Mapped, mapped_column
from sqlalchemy import String, Boolean, Integer, ForeignKey, Text

from db.db_base import BaseModel

from apps.vadmin.auth.models import VadminUser

class KnowledgeBaseDB(BaseModel):
    __tablename__ = "crewplus_knowledge_base"
    __table_args__ = ({'comment': 'knowledge base for rag'},)

    parent_id: Mapped[int] = mapped_column(Integer, nullable=True, comment="parent Knowledge base id")
    
    name: Mapped[str] = mapped_column(String(255), nullable=False, comment="Knowledge base name, used as collection_name in Milvus")
    description: Mapped[str] = mapped_column(Text, comment="knowledge base description")

    is_active: Mapped[bool] = mapped_column(Boolean, default=True, comment="active flag")
    
    create_user_id: Mapped[int] = mapped_column(
        Integer,
        ForeignKey("vadmin_auth_user.id", ondelete='RESTRICT'),
        comment="create user id"
    )
    create_user: Mapped[VadminUser] = relationship(foreign_keys=create_user_id)

    # @Description: add collection id and collection name from saas, steven, 2025-01-06
    coll_id: Mapped[int] = mapped_column(Integer, nullable=True, comment="collection id from saas")
    coll_name: Mapped[str] = mapped_column(String(255), nullable=True, comment="collection name from saas")
